package dev.ece.core.light;

import org.lwjgl.opengl.GL20;
/**
 * 材料shader location handler
 * @author 飘渺青衣
 * <b>E-mail：</b>3375758@qq.com
 */
public class MaterialLocationHandler {

	private int enableHandler;
	/**
	 * 散射光
	 */
	private int diffuseHandler;
	
	/**
	 * 高光元素
	 */
	private int specularHandler;
	
	private int shininessHandler;
	
	private int alphaHandler;

	private MaterialLocationHandler() {}
	
	public static MaterialLocationHandler newInstance(int program, String prefix) {
		MaterialLocationHandler handler = new MaterialLocationHandler();
		handler.enableHandler = GL20.glGetUniformLocation(program, prefix.concat("enable"));
		handler.diffuseHandler = GL20.glGetUniformLocation(program, prefix.concat("diffuse"));
		handler.specularHandler = GL20.glGetUniformLocation(program, prefix.concat("specular"));
		handler.shininessHandler = GL20.glGetUniformLocation(program, prefix.concat("shininess"));
		handler.alphaHandler = GL20.glGetUniformLocation(program, prefix.concat("alpha"));
		return handler;
	}
	
	public void glUniformMaterial(Material material) {
		material.glUniformMaterial(this);
	}
	
	public int getDiffuseHandler() {
		return diffuseHandler;
	}

	public int getSpecularHandler() {
		return specularHandler;
	}

	public int getShininessHandler() {
		return shininessHandler;
	}

	public int getAlphaHandler() {
		return alphaHandler;
	}

	protected void setDiffuseHandler(int diffuseHandler) {
		this.diffuseHandler = diffuseHandler;
	}

	protected void setSpecularHandler(int specularHandler) {
		this.specularHandler = specularHandler;
	}

	protected void setShininessHandler(int shininessHandler) {
		this.shininessHandler = shininessHandler;
	}

	protected void setAlphaHandler(int alphaHandler) {
		this.alphaHandler = alphaHandler;
	}

	public int getEnableHandler() {
		return enableHandler;
	}
	
	public void clearup() {
		GL20.glDeleteShader(enableHandler);
		GL20.glDeleteShader(diffuseHandler);
		GL20.glDeleteShader(specularHandler);
		GL20.glDeleteShader(shininessHandler);
	}
	
}
